package com.qianyu.project.service.impl;

import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.MaterialInstorageRecord;
import com.qianyu.project.entity.MaterialInstorageRecordDetail;
import com.qianyu.project.mapper.MaterialInstorageRecordMapper;
import com.qianyu.project.service.IMaterialInstorageRecordDetailService;
import com.qianyu.project.service.IMaterialInstorageRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 材料入库记录 服务实现类
 * </p>
 *
 * @author gs
 * @since 2021-01-30
 */
@Service
public class MaterialInstorageRecordServiceImpl extends ServiceImpl<MaterialInstorageRecordMapper, MaterialInstorageRecord> implements IMaterialInstorageRecordService {

    @Autowired
    private MaterialInstorageRecordMapper mapper;
    @Autowired
    private IMaterialInstorageRecordDetailService detailService;
    /**
     材料入库
     * description:  <br/>
     * author: lyz   <br/>
     * date: 2021/2/10 <br/>
     * params:  <br/>
     * return:
     */
    @Override
    @FlowBegin("material_storage_record")
    public void saveInstorage(@FlowEntry("id") MaterialInstorageRecord instorage,
                              List<MaterialInstorageRecordDetail> dlist) {
        mapper.insert(instorage);
        dlist.forEach(d->{
            d.setInstorageId(instorage.getId());
        });
        detailService.saveBatch(dlist);
    }
}
